package com.thirteengroup.casemg.controller;


import com.thirteengroup.casemg.domain.*;
import com.thirteengroup.casemg.service.impl.TraceHistoryService;
import com.thirteengroup.casemg.service.impl.ddetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author 28464
 */
@Controller
@RequestMapping("/tracehistory")
public class tracehistoryController {

    @Autowired
    TraceHistoryService traceHistoryService;

    @Autowired
    ddetailService ddetailService;

    @GetMapping("list")
    @ResponseBody
    public JasonResult ListLimit(queryObject queryObject){
        List<tracehistory> tracehistories = traceHistoryService.queryAllLimit(queryObject);
        Integer totalCount=traceHistoryService.queryCount();
        PageResult<tracehistory> pageResult=new PageResult<>(queryObject.getCurrentPage(),totalCount, queryObject.getPageSize(), tracehistories);
        JasonResult jasonResult=new JasonResult("查询跟进历史成功",true,pageResult);
        return jasonResult;
    }

    @PostMapping("delete")
    @ResponseBody
    public JasonResult deleteTra(Long id){
        traceHistoryService.delete(id);
        return new JasonResult("删除成功",true,null);
    }

    @PostMapping("upOrin")
    @ResponseBody
    public JasonResult upOrin(tracehistory ty){

        Long id = ty.getId();
        //新增和更新时添加当前时间（此处不实现，在数据库使用now()函数实现）
        if(id==null){//insert

            traceHistoryService.insert(ty);
            return new JasonResult("新增成功",true,null);
        }else {//更新
            traceHistoryService.update(ty);
            return new JasonResult("更新成功",true,null);
        }
    }

    @ResponseBody
    @RequestMapping("/getDdetail")
    public JasonResult getDdetail(String dmname){
        List<ddetail> ddetailList= ddetailService.queryAll(dmname);
        JasonResult jasonResult=new JasonResult("跟进方式获取成功",true,ddetailList);
        return jasonResult;
    }


}
